<style>
.dragStyle{
	background-color:#afba9b;
}
</style>
<script type="text/javascript" src="assets/js/jquery.tablednd.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	
	$("#courseForm").submit(function(){return formVal()});
	$("#tableHoleList").tableDnD({onDragClass: "dragStyle"});

	var aVal = new Array();
	$("input[name=hdnHoleId]").each(function(){
		aVal.push($(this).val());
	});
});

function formVal(){
	var aErrors = new Array();

	if($("#txtBxCourseName").val().trim() == "")
		aErrors.push("* Course name must not be blank.");

 	if($("#ddVenueList").val() == "")
 		aErrors.push("* Venue must be selected");

 	var sErrorMsg = aErrors.join("\n");

	if(sErrorMsg != "")
		alert(sErrorMsg);
		
	return (!(sErrorMsg != ""));
}

</script>

<h3 style="margin:0">Course Management</h3>
<?php printf("<a href=\"?%s\">&lt; Back to the list</a>",AdminItemEnum::COURSES);?>
<form id="courseForm" name="courseForm" action="index.php" method="POST">
<input type="hidden" name="<?php echo AdminItemEnum::COURSES?>"/>
<input type="hidden" name="edit"/>
<input type="hidden" name="courseid" value="<?php echo $courseid;?>"/>
<table width="100%" cellspacing="0" cellpadding="0" border="1">
	<tr style="background-color:#afba9b">
		<td align="right" colspan="2">
			<input type="button" name="btnCancelCourseEdit" value="Cancel" onclick="location.href='?<?php echo AdminItemEnum::COURSES;?>'"/>
			<inpuy type="button" name="btnChangeOrder" value="Change Order" onclick="location.href='?<?php echo AdminItemEnum::COURSES;?>'"/>
			<input type="submit" name="btnSaveCourse" value="Save"/>
		</td>
	</tr>
	<tr>
		<td align="right" width="10%">Course Name:</td>
		<td><input type="text" id="txtBxCourseName" name="txtBxCourseName" value="<?php echo $course->coursename;?>"/>
	</tr>
	<tr>
		<td align="right">Venue:</td>
		<td>
			<select id="ddVenueList" name="ddVenueList">
				<option value="">Select</option>
				<?php 
					foreach($venuelist as $v){
						$selected = ($v->venueid == $course->venue->venueid)?" selected":"";
						printf("<option value=\"%s\"%s>%s</option>",$v->venueid,$selected,$v->venuename);
					}	
				?>
			</select>	
		</td>
	</tr>
	<tr>
		<td align="right" valign="top">Holes:</td>
		<td valign="top">
			<table id="tableHoleList" width="100%" border="1">
				<tr>
					<th>Hole Name</th>
					<th>Par</th>
					<th>Order</th>
				</tr>
				<?php
					$c = 0;
					foreach ($holelist as $h){
						$c++;
						printf("<tr id=\"row-%s\">",$c);
						echo "	<td>";
						printf("<input type=\"hidden\" name=\"hdnHoleId\" value=\"%s\"/>",$h->holeid);
						echo $h->holename;
						echo "	</td>";
						printf("	<td>%s</td>",$h->par);
						printf("	<td>%s</td>",$h->holeorder);
						echo "</tr>\n";
					}
				?>
			</table>
		</td>
	</tr>
	<tr>
		<td align="right" colspan="2">
			<input type="button" name="btnCancelCourseEdit" value="Cancel" onclick="location.href='?<?php echo AdminItemEnum::COURSES;?>'"/>
			<input type="submit" name="btnSaveCourse" value="Save"/>
		</td>
	</tr>
</table>
</form>